
function selectInvoice(){
	var invoiceCid = escape(escape(document.getElementById('invoiceCid').value));
	var type = escape(escape(document.getElementById('type').value));
	var begin_date = escape(escape(document.getElementById('begin_date').value));
	var end_date = escape(escape(document.getElementById('end_date').value));
	
	var url = '/storage/manager/pages/invoice.do?method=selectInvoice&d=' + new Date();
	url = url + '&invoiceCid=' + invoiceCid;
	url = url + '&type=' + type;
	url = url + '&begin_date=' + begin_date;
	url = url + '&end_date=' + end_date;
	
	$.getJSON(url, {}, function(data){
		$('#invoice_list').html('');
		
		var _max = get_max_line(190,25);
		for(var i=0;i<data.length;i++){
			var style_border = 0-(0-i-1)==data.length&&data.length>=_max?'style="border-bottom:0;"':'';
			var invoiceList = '';
			var ttype = data[i][3]=='11'?'买':data[i][3]=='12'?'还':data[i][3]=='21'?'卖':data[i][3]=='22'?'借':'';
			invoiceList = invoiceList + '<tr style="height:25px; cursor:pointer;" onclick="selectInvoiceItem('+data[i][0]+')" onmouseover="cbgcolor(this,0)" onmouseout="cbgcolor(this,1)">';
			invoiceList = invoiceList + ' <td class="list" '+style_border+' width="100">'+data[i][1]+'</td>';
			invoiceList = invoiceList + ' <td class="list" '+style_border+' width=""   >'+(data[i][2]==null?'':data[i][2])+'</td>';
			invoiceList = invoiceList + ' <td class="list" '+style_border+' width="60" >'+ttype     +'</td>';
			invoiceList = invoiceList + ' <td class="list" '+style_border+' width="80" >'+data[i][4]+'</td>';
			invoiceList = invoiceList + ' <td class="list" '+style_border+' width="80" >'+data[i][5]+'</td>';
			invoiceList = invoiceList + ' <td class="list" '+style_border+' width="80" >'+data[i][6]+'</td>';
			invoiceList = invoiceList + ' <td class="list" '+style_border+' width="80" >'+(data[i][7]==null?'':data[i][7])+'</td>';
			invoiceList = invoiceList + ' <td class="list" '+style_border+' width="80" >'+data[i][8]+'</td>';
			invoiceList = invoiceList + ' <td class="list" '+style_border+' width="100">'+data[i][9]+'</td>';
			invoiceList = invoiceList + '</tr>';
			$('#invoice_list').append(invoiceList);
		}
		if(data.length<_max){
			add_foot();
		}
	});
};
function add_foot(){
	var foot = '';
    foot = foot + '<tr>';
	foot = foot + '  <td class="list" style="border-bottom:0;" width="100">&nbsp;</td>';
	foot = foot + '  <td class="list" style="border-bottom:0;" width="">&nbsp;</td>';
	foot = foot + '  <td class="list" style="border-bottom:0;" width="60">&nbsp;</td>';
	foot = foot + '  <td class="list" style="border-bottom:0;" width="80">&nbsp;</td>';
	foot = foot + '  <td class="list" style="border-bottom:0;" width="80">&nbsp;</td>';
	foot = foot + '  <td class="list" style="border-bottom:0;" width="80">&nbsp;</td>';
	foot = foot + '  <td class="list" style="border-bottom:0;" width="80">&nbsp;</td>';
	foot = foot + '  <td class="list" style="border-bottom:0;" width="80">&nbsp;</td>';
	foot = foot + '  <td class="list" style="border-bottom:0;" width="100">&nbsp;</td>';
	foot = foot + '</tr>';
	$('#invoice_list').append(foot);
};
function selectInvoiceItem(invoice_id){
	
	var url = '/storage/manager/pages/invoice.do?method=selectInvoiceItems&d=' + new Date();
	url = url + '&invoice_id=' + invoice_id;
	
	$.getJSON(url, {}, function(data){
		$('#invoice_item_list').html('');
		
		var _max = get_max_line(200,25);
		for(var i=0;i<data.length;i++){
			var style_border = 0-(0-i-1)==data.length&&data.length>=_max?'style="border-bottom:0;"':'';
			var invoiceItemList = '';
			invoiceItemList = invoiceItemList + '<tr style="height:25px;" onmouseover="cbgcolor(this,0)" onmouseout="cbgcolor(this,1)">';
			invoiceItemList = invoiceItemList + ' <td class="list" '+style_border+' width="200">' + data[i][0] + '</td>';
			invoiceItemList = invoiceItemList + ' <td class="list" '+style_border+' width=""   >' + data[i][1] + '</td>';
			invoiceItemList = invoiceItemList + ' <td class="list" '+style_border+' width="100">' + data[i][2] + '</td>';
			invoiceItemList = invoiceItemList + ' <td class="list" '+style_border+' width="100">' + data[i][3] + '</td>';
			invoiceItemList = invoiceItemList + ' <td class="list" '+style_border+' width="50" >' + data[i][4] + '</td>';
			invoiceItemList = invoiceItemList + ' <td class="list" '+style_border+' width="100">' + data[i][5] + '</td>';
			invoiceItemList = invoiceItemList + '</tr>';
			$('#invoice_item_list').append(invoiceItemList);
		}
		if(data.length<_max){
			add_item_foot();
		}
	});
};
function add_item_foot(){
	var foot = '';
    foot = foot + '<tr>';
	foot = foot + '  <td class="list" style="border-bottom:0;" width="200">&nbsp;</td>';
	foot = foot + '  <td class="list" style="border-bottom:0;" width="">&nbsp;</td>';
	foot = foot + '  <td class="list" style="border-bottom:0;" width="100">&nbsp;</td>';
	foot = foot + '  <td class="list" style="border-bottom:0;" width="100">&nbsp;</td>';
	foot = foot + '  <td class="list" style="border-bottom:0;" width="50">&nbsp;</td>';
	foot = foot + '  <td class="list" style="border-bottom:0;" width="100">&nbsp;</td>';
	foot = foot + '</tr>';
	$('#invoice_item_list').append(foot);
};